#include <stdio.h>
#include <stdlib.h>

 // Definition for a binary tree node.
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
};


int maxDepth(struct TreeNode* root) {
    if (root == NULL) return 0;
    int left = maxDepth(root->left);
    int right = maxDepth(root->right);
    return (left > right ? left : right) + 1;
}


int main() {
    struct TreeNode *left = malloc(sizeof(struct TreeNode));
    left->val = 1;
    struct TreeNode *right = malloc(sizeof(struct TreeNode));
    right->val = 2;
    struct TreeNode *right_right = malloc(sizeof(struct TreeNode));
    right_right->val = 3;
    right->right = right_right;
    struct TreeNode *right_right_right = malloc(sizeof(struct TreeNode));
    right_right_right->val = 4;
    right_right->right = right_right_right;
    struct TreeNode *left_right = malloc(sizeof(struct TreeNode));
    left_right->val = 5;
    left->right = left_right;


    struct TreeNode *root = malloc(sizeof(struct TreeNode));
    root->val = 0;
    root->left = left;
    root->right = right;
    int res = maxDepth(root);
    free(root);
    free(left);
    free(right);
    free(right_right);
    free(right_right_right);
    printf("depth = %d\n", res);
    return 0;
}